<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "asr_keyword_xtlc_classify".
 *
 * @property int $id 系统流程的表
 * @property string $name 名字
 * @property int $audio_id 所属流程的ID
 * @property string $file_id 文件IDs
 * @property int $parent_id 父ID
 * @property int $intent_score 意向得分分
 * @property int $before_id 上一个节点的id
 * @property string $scene_word 所属语境
 * @property string $keywords 关键词
 * @property string $parse_words 解析语句
 * @property string $scene_factor 场景因素
 * @property int $keywords_scope 关键字的使用范围 当为0时代表的是所有的都有效
 * @property int $type 类型
 */
class AsrKeywordXtlcClassify extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'asr_keyword_xtlc_classify';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['audio_id', 'parent_id', 'intent_score', 'before_id', 'keywords_scope', 'type'], 'integer'],
            [['scene_word', 'keywords', 'parse_words', 'scene_factor'], 'string'],
            [['name'], 'string', 'max' => 40],
            [['file_id'], 'string', 'max' => 500],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'audio_id' => 'Audio ID',
            'file_id' => 'File ID',
            'parent_id' => 'Parent ID',
            'intent_score' => 'Intent Score',
            'before_id' => 'Before ID',
            'scene_word' => 'Scene Word',
            'keywords' => 'Keywords',
            'parse_words' => 'Parse Words',
            'scene_factor' => 'Scene Factor',
            'keywords_scope' => 'Keywords Scope',
            'type' => 'Type',
        ];
    }

    /**
     *遍历出各个子类 获得树状结构的数组
     */
    public static function getTree($data,$pid = 0,$lev = 1)
    {
        $tree = [];
        foreach($data as $value){
            if($value['parent_id'] == $pid){
                $value['name'] = str_repeat('',$lev).$value['name'];
                $value['level'] = $lev;
                $tree[] = $value;
                $tree = array_merge($tree,self::getTree($data,$value['id'],$lev+1));
            }
        }
        return $tree;
    }
}
